package com.lm.mapstruct.example;

import com.lm.mapstruct.dto.UserDTO;
import com.lm.mapstruct.entry.Address;
import com.lm.mapstruct.entry.User;
import com.lm.mapstruct.mapper.UserMapper;
import org.mapstruct.factory.Mappers;

public class UserExample {
    public static void main(String[] args) {
        UserMapper mapper = Mappers.getMapper(UserMapper.class);

        // 模拟 User 对象
        User user = new User();
        user.setId(1L);
        user.setName("John");
        user.setEmail("john@example.com");
        Address address = new Address();
        address.setCity("New York");
        user.setAddress(address);

        // 转换为 DTO
        UserDTO userDTO = mapper.userToUserDTO(user);
        System.out.println("UserDTO: " + userDTO);

        // DTO 转换回实体
        User newUser = mapper.userDTOToUser(userDTO);
        System.out.println("User: " + newUser);
    }
}
